package sh.grapendaal.tsuushin.core;

import sh.grapendaal.tsuushin.message.IncomingMessage;

/**
 * Keeps track of all data to do with a command. This includes its trigger, the
 * permission needed and of course the callback which is invoked when the
 * command is activated.
 */
public class Command {
	private String trigger;
	private String permission;
	private RunnableCommand callback;

	/**
	 * Constructs a new command.
	 * 
	 * @param trigger
	 *            The trigger for this command.
	 * @param permission
	 *            The permission needed for this command.
	 * @param callback
	 *            The callback with the code to execute.
	 */
	public Command(String trigger, String permission, RunnableCommand callback) {
		this.trigger = trigger;
		this.permission = permission;
		this.callback = callback;
	}

	/**
	 * Returns the trigger which this command listens to.
	 * 
	 * @return The trigger of this command.
	 */
	public String getTrigger() {
		return this.trigger;
	}

	/**
	 * Returns the permission needed by the user in order to execute this
	 * command.
	 * 
	 * @return The required permission.
	 */
	public String getPermission() {
		return this.permission;
	}

	/**
	 * Executes the command.
	 * 
	 * @param context
	 *            The current context.
	 * @param message
	 *            The received message.
	 * @return Boolean indicating whether processing should continue.
	 */
	public boolean execute(Context context, IncomingMessage message) {
		return this.callback.run(context, message);
	}
}
